package com.draby.starfantasymaze.dto.map;

import com.draby.starfantasymaze.enums.StatusCode;

import org.jetbrains.annotations.NotNull;

import java.io.Serializable;
import java.util.Objects;

public class Block implements Serializable {
    /* 是否能向 上 移动 */
    private Boolean canUp;
    /* 是否能向 右 移动 */
    private Boolean canRight;
    /* 是否能向 下 移动 */
    private Boolean canDown;
    /* 是否能向 左 移动 */
    private Boolean canLeft;
    /* 本格状态代码 */
    private StatusCode statusCode;
    /* 格子在地图中的 行索引 */
    private Integer rowIdx;
    /* 格子在地图中的 列索引 */
    private Integer colIdx;
    /* 格子的背景颜色，默认透明0x00000000 */
    private int backgroundColor;

    public Boolean getCanUp() {
        return canUp;
    }

    public void setCanUp(Boolean canUp) {
        this.canUp = canUp;
    }

    public Boolean getCanRight() {
        return canRight;
    }

    public void setCanRight(Boolean canRight) {
        this.canRight = canRight;
    }

    public Boolean getCanDown() {
        return canDown;
    }

    public void setCanDown(Boolean canDown) {
        this.canDown = canDown;
    }

    public Boolean getCanLeft() {
        return canLeft;
    }

    public void setCanLeft(Boolean canLeft) {
        this.canLeft = canLeft;
    }

    public StatusCode getStatusCode() {
        return statusCode;
    }

    public void setStatusCode(StatusCode statusCode) {
        this.statusCode = statusCode;
    }

    public Integer getRowIdx() {
        return rowIdx;
    }

    public Integer getColIdx() {
        return colIdx;
    }

    public int getBackgroundColor() {
        return backgroundColor;
    }

    public void setBackgroundColor(int backgroundColor) {
        this.backgroundColor = backgroundColor;
    }

    /**
     * 无参构造函数，初始化格子信息
     */
    public Block() {
        canUp = false;
        canDown = false;
        canLeft = false;
        canRight = false;
        statusCode = StatusCode.UNVISITED;
        backgroundColor = 0x00000000;
    }

    /**
     * 带两个参数的构造函数，初始化格子在地图中的行列索引
     * @param rowIdx 格子在地图中的行索引
     * @param colIdx 格子在地图中的列索引
     */
    public Block(Integer rowIdx, Integer colIdx) {
        this();
        this.rowIdx = rowIdx;
        this.colIdx = colIdx;
    }

    @Override
    public @NotNull String toString() {
        return "向上: " + canUp +
                ", 向下: " + canDown +
                ", 向左: " + canLeft +
                ", 向右: " + canRight +
                ", 状态: " + statusCode.getDescription();
    }

    @Override
    public boolean equals(Object object) {
        if (this == object) return true;
        if (object == null || getClass() != object.getClass()) return false;
        Block block = (Block) object;
        return backgroundColor == block.backgroundColor &&
                Objects.equals(canUp, block.canUp) &&
                Objects.equals(canRight, block.canRight) &&
                Objects.equals(canDown, block.canDown) &&
                Objects.equals(canLeft, block.canLeft) &&
                statusCode == block.statusCode &&
                Objects.equals(rowIdx, block.rowIdx) &&
                Objects.equals(colIdx, block.colIdx);
    }

    @Override
    public int hashCode() {
        return Objects.hash(canUp, canRight, canDown, canLeft, statusCode, rowIdx, colIdx, backgroundColor);
    }
}
